package net.begincode;

import com.google.common.collect.Lists;
import net.begincode.blog.entity.User;
import net.begincode.common.ApiResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/begincode/")
public class CommonController {
    @RequestMapping(value = "login")
    private ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login");
        return modelAndView;
    }
    @RequestMapping(value = "reg")
    private ModelAndView reg(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("reg");
        return modelAndView;
    }
    @RequestMapping(value = "admin")
    private ModelAndView admin(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("admin");
        return modelAndView;
    }

    @RequestMapping("/index")
    @ResponseBody
    public ApiResponse<List<User>> table() {

        List<User> users = getUser();
        return ApiResponse.success(users, users.size());
    }
    private List<User> getUser() {
        User user = new User();
        user.setId(123L);
        user.setSex("男");
        user.setCdate(new Date());
        user.setEmail("yangsj");
        return Lists.newArrayList(user, user);
    }
}
